package logic

import (
	"context"
	"fmt"
	"shuqi_novel/models"

	"shuqi_novel/shop_rpc/internal/svc"
	"shuqi_novel/shop_rpc/shop_rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewBookAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookAddLogic {
	return &BookAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *BookAddLogic) BookAdd(in *shop_rpc.BookAddRequest) (*shop_rpc.BookAddResponse, error) {
	// todo: add your logic here and delete this line
	var book models.Book
	book.Title = in.Title
	book.Type = in.Type
	book.AuthorId = int(in.AuthorId)
	if models.DB.Create(&book).Error != nil {
		return nil, fmt.Errorf("服务器繁忙")
	}
	return &shop_rpc.BookAddResponse{}, nil
}
